﻿Option Explicit On

Imports OfekInventory.Microsoft.Office.Interop.Excel

Public Class DLGimport

    Private _
        oExcel As Excel.Application, _
        oWorkbook As Excel.Workbook, _
        oWorkSheet As Excel.Worksheet

    Private sFilePath As String

    ' Initialize the form, open the selected Excel file, and load the worksheet names into the list box ----------------------------------------------------

    Public Sub init(ByVal sFilePath As String)

        'On Error Resume Next

        'oExcel = New Excel.Application

        'If Err.Number <> 0 Then

        '    logMessage( _
        '        1, _
        '        "DLGimport", _
        '        "Could not create new Excel application", _
        '        String.Empty, _
        '        Err.Number, _
        '        Err.Description)

        'Else

        '    logMessage( _
        '        5, _
        '        "DLGimport", _
        '        "Created new Excel object")

        'End If

        'On Error Resume Next

        'oWorkbook = oExcel.Workbooks.Open(sFilePath)

        'If Err.Number <> 0 Then

        '    logMessage( _
        '        1, _
        '        "DLGimport", _
        '        "Could not open workbook for importing from Excel", _
        '        "File path = " & sFilePath, _
        '        Err.Number, _
        '        Err.Description)

        'Else

        '    logMessage( _
        '        3, _
        '        "DLGimport", _
        '        "Opened workbook for importing from Excel", _
        '        "File path = " & sFilePath)

        'End If

        'LISTworksheets.Items.Clear()

        'For Each oWorkSheet In oWorkbook.Worksheets

        '    LISTworksheets.Items.Add(oWorkSheet.Name)

        'Next

        'LISTworksheets.SelectedIndex = 0

        'Me.TXTimportFrom.Text = sFilePath

        'Me.Show(FRMmain)
        Throw New NotImplementedException
    End Sub

    ' Events ----------------------------------------------------------------------------------------------------------------------

    Private Sub CMDbrowse_Click()

        On Error Resume Next

        Close()

        FRMmain.fileImport_Click()

    End Sub


    Private Sub CMDcancel_Click()

        On Error Resume Next

        oExcel.Quit()

        Close()

    End Sub

    Private Sub CMDimport_Click()

        On Error Resume Next

        MODimport.importFromExcel(oWorkbook, LISTworksheets.SelectedIndex)

    End Sub

End Class